package com.woniuxy.creditsystem.statisticsmag.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.creditsystem.common.bean.FinanceInfo;
import com.woniuxy.creditsystem.common.mapper.FinanceMapper;
import com.woniuxy.creditsystem.statisticsmag.page.PageRequest;
import com.woniuxy.creditsystem.statisticsmag.service.IFinanceService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Transactional(readOnly = true)
@Service
public class FinanceServiceImpl implements IFinanceService {
    @Resource
    private FinanceMapper financeMapper;

    /**
     * 查询所有的财务统计信息
     *
     * @return 财务统计集合
     */
    @Override
    public List<FinanceInfo> findAll() {
        return financeMapper.findAll();
    }


    /**
     * 添加每日的财务统计信息
     * @param financeInfo
     * @return 受影响的行数
     */
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int saveFinance(FinanceInfo financeInfo) {
        return financeMapper.saveFinance(financeInfo);
    }


    /**
     * 根据参数进行分页查询
     * @param request 分页请求对象
     * @param  financeInfo 条件
     * @return
     */
    @Override
    public PageInfo<FinanceInfo> findAllByParams(PageRequest request, FinanceInfo financeInfo) {
        return PageHelper.startPage(request.getPageNum(),request.getLimit()).
                doSelectPageInfo(()->financeMapper.findAllByParams(request,financeInfo));
    }

    @Override
    public List<FinanceInfo> findMonDataDs() {
        return financeMapper.findMonDataDs();
    }

    @Override
    public List<FinanceInfo> findMonDataHk() {
        return financeMapper.findMonDataHk();
    }

    @Override
    public List<FinanceInfo> findMonDataYq() {
        return financeMapper.findMonDataYq();
    }
}
